<template>
  <div class="pageList">
   <TheTable
      ref="TheTableRef"
      :tableApi="evaluationListApi"
      :searchList="searchList"
			:listColumns="listColumns"
			:actionArr="actionArr"
			@handleClick="handleClick"
    />
     <div class="pageFooterBtn">
      <el-button @click="$router.back()">返 回</el-button>
    </div>
  </div>
</template>
<script>
import { evaluationListApi, evaluationDelApi } from '@/api/workbench/index'
import TheTable from '@/componentsView/TheTable.vue';
export default{
  components: { TheTable },
  data() {
    return {
      evaluationListApi,
      evaluationDelApi,
      searchList: [
        {
          type: 'input',
          name: '教师姓名',
          field: 'teacherName',
        },
      ],
      listColumns: [
        {
          title: '教师姓名',
          key: 'teacherName',
        },
        {
          title: '所属学院',
          key: 'deptName',
        },
        {
          title: '评价发起方',
          key: 'evaluationTypeName',
        },
        {
          title: '综合评分',
          key: 'totalScore',
        },
        {
          title: '评价提交时间',
          key: 'createTime',
        },
      ],
      actionArr: [
        {
          action: 'look',
          value: '查看',
        },
        {
          action: 'del',
          value: '删除',
        },
      ],
      urlList: {
        192: '/intelligentEvaluation/supervisor/detail',
        193: '/intelligentEvaluation/teacherSelf/detail',
        194: '/intelligentEvaluation/teacherPeer/detail',
        195: '/intelligentEvaluation/parent/detail',
        196: '/intelligentEvaluation/student/detail',
      },
    }
  },
  created() {
  },
  methods: {
    setTableList(){
      this.$refs.TheTableRef.resetQuery()
    },
    handleClick({record,action}){
      switch(action) {
        case 'look':
          this.goToDetail  (record)
          break;
        case 'del':
          this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.delFun(record.evaluationId);
          }).catch(() => {
            this.$message.info('已取消删除');
          });
          break;
        default:
          break;
      }
    },
    goToDetail  (record){
      let path = this.urlList[record.evaluationTypeId] + '?evaluationId=' + record.evaluationId + '&action=look';
      this.$router.push(path)
    },
    delFun(evaluationId) {
      evaluationDelApi(evaluationId).then(res=>{
        if (res.code === 200) {
          this.$message.success(res.msg)
          this.setTableList()
        } else {
          this.$message.error(res.msg)
        }
      })
    }
  }
}
</script>
